home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d12
/
cgazv5n5.arc
/
LIST1.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-09-23
|
1KB
|
50 lines
/*---------------------------------------- Listing 1 ------
* Demonstration of atexit().
* by Thomas Siering
*
* (c) 1991 C Gazette. Object code may be freely used,
* source code may be used if authorship and publication
* are acknowledged.
*-------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
void ReleaseFile ( void );
void FreeMemory ( void );
void main ( void );
FILE *File;
void *Memory;
void main()
{
/* Open a file and provide for its closing
at ANY subsequent time. */
if (( File = fopen ( "FILE.DAT", "w" )) == NULL )
return;
if ( atexit ( ReleaseFile ) != 0 ) /* = 0 if installed OK */
return;
/* Do likewise for memory */
if (( Memory = malloc ( 10 )) == NULL )
return;
if ( atexit ( FreeMemory ) != 0 )
return;
}
void ReleaseFile()
{
if ( fclose ( File ) != 0 )
fprintf ( stderr, "File FILE.DAT not closed\n" );
else
fprintf ( stdout, "File FILE.DAT has been closed\n" );
}
void FreeMemory()
{
free ( Memory );
fprintf ( stdout, "Memory freed\n" );
}